$(function(){

	$("#typeIco_upload_button").swfupload(CTX,
		{	
        	button_width : 70,
        	button_height : 30,
        	button_text_left_padding : 20,
	        button_text_top_padding : 0.4,
	        button_text : "上传",
			upload_url : fileUploadUrl,
			progress_bar : $("#upload_progress ul"),
			file_dialog_complete_handler : function(countFile,countAddFile,countAllFile){
				//根据接口文档，定义所需 参数  
				var options ={
					"path": "/shop/"+shopId+"/goods/type",
					"rename":"true"
				};
				this.setPostParams(options);
				//设定上传文件类型及说明
				var types = "*.jpg;*.gif;*.png";
				this.setFileTypes(types, "请选择");
				//设定上传文件体积,合法的单位有:B、KB、MB、GB，如果省略了单位，则默认为KB。该属性为0时，表示不限制文件的大小。
				this.setFileSizeLimit("2MB");
				this.startUpload();
			},
			upload_success_handler :function(file,data,response){
				var dataObj = eval('(' + data + ')');
				var dataPath="";
				if(dataObj.code == "1"){
						if(dataObj.files[0].repCode=="1"){
							dataPath = dataObj.files[0].path;
							$("#typeIcon p").html("<img src="+fileOpenUrl + dataPath+" id='typeIcon"+file.index+"' />" +
									"<input type='hidden' value='"+dataPath+"' name='erpMerchandiseType.iconUrl'></input>");
						}else{
							alert("上传失败："+dataObj.files[0].repMsg);
						}
				}else{
					alert("文件上传失败："+dataObj.msg);
				}
			},
			upload_complete_handler :function(file){
				this.startUpload();
			}
			
		}
	);
});


//查询二级分类
function findTypeForId(secId){
	$("#secTypeSelect [value!='']").remove();
	
	var parentId = $('#dUnitSelect option:selected').val();
	jQuery.ajax({
			url: CTX+"/shop/Merchandise/findTypeForId.do",
			type:"POST",
			data:"parentId="+parentId+"&shopId="+shopId,
			success:function(data){	
				for(var i in data){
					if(secId!=null&&data[i].merchandiseTypeId == secId){
						$("#secTypeSelect").append('<option selected="selected" value="'+data[i].merchandiseTypeId+'">'+data[i].merchandiseTypeName+'</option>');
					}else{
						$("#secTypeSelect").append('<option value="'+data[i].merchandiseTypeId+'">'+data[i].merchandiseTypeName+'</option>');
					}
				}
					
			}
		});
}